
import dayjs from 'dayjs';
import ObsClient from 'esdk-obs-browserjs';



export const  OBSENUM= {
  BUCKET : "juexiao-time",
  Prefix : "jx_tester/CasePics/",
  UrlPre:"https://img.juexiaotime.com/"
}

const obsClient = new ObsClient({
  access_key_id: 'JKF5BJANQMRPSK5RCSIC',
  secret_access_key: '1t7TWXtnYYWw0I35HbLFbAB0BkAt76fi6w6ninTd',
  server: 'https://obs.cn-east-3.myhuaweicloud.com',
  // server:'https://img.juexiaotime.com/'

});


export const upLoadToObs = async (objectkey, SourceFile) => {


  return new Promise((resolve, reject) => {
    setTimeout(() => {
      obsClient.putObject({
        Bucket: OBSENUM.BUCKET,
        Key: objectkey,
        SourceFile: SourceFile
      }, function (err, result) {
        if (err) {
          console.error('Error-->' + err);
          reject("上传失败！");
        } else {
          if (result.CommonMsg.Status < 300) {
            // console.log('RequestId-->' + result.InterfaceResult.RequestId);
            // console.log('ETag-->' + result.InterfaceResult.ETag);
            // console.log('VersionId-->' + result.InterfaceResult.VersionId);
            // console.log('StorageClass-->' + result.InterfaceResult.StorageClass);
          } else {
            // console.log('Code-->' + result.CommonMsg.Code);
            // console.log('Message-->' + result.CommonMsg.Message);

          }
          resolve(objectkey);
        }

      });

    }, 500);

  });
}






